/*!
 * 该mixin 主要服务于流程toolbar
 * 
 */
import { request } from 'utils/http'
import { serialize } from 'utils'

const Mixin_Toolbar =  {
  data() {
    return {
      url: {
        "do_start": "/sys/emapflow/tasks/startFlow.do",
        "do_submit": "/sys/emapflow/tasks/execute.do",
        "do_termination": "/sys/emapflow/tasks/terminateInstance.do",
        "do_change_assignee": "/sys/emapflow/tasks/changeAssignee.do",
        "do_turnback": "/sys/emapflow/tasks/turnback.do",
        "do_callback": "/sys/emapflow/tasks/callback.do",
        "do_process_status": "/sys/emapflow/tasks/queryFlowState.do",
        "do_custom": "/sys/emapflow/tasks/custom.do",
        "do_urgent": "/sys/emapflow/tasks/urgent.do",
        "do_process_track": "/sys/emapflow/tasks/queryFlowTrack.do"
      }
    }
  },
  methods: {
    // 启动
    do_start(item, query) {
      let url = item.url || this.url[item.execute];
      return this.promiseFun(url, query)
    },
    // 提交
    do_submit(item, query) {
      let url = item.url || this.url[item.execute];
      return this.promiseFun(url, query)
    },
    //  终止
    do_termination(item, query) {
      let url = item.url || this.url[item.execute];
      return this.promiseFun(url, query)
    },
    // 退回
    do_turnback(item, query) {
      let url = item.url || this.url[item.execute];
      return this.promiseFun(url, query)
    },
    // 追回
    do_callback(item, query) {
      let url = item.url || this.url[item.execute];
      return this.promiseFun(url, query)
    },
    promiseFun(url, query) {
      return new Promise( resolve => {
        request(url, {
          method: "POST",
          data: serialize(query),
          headers: {
            "content-type": "application/x-www-form-urlencoded"
          }
        }).then(res => {
          resolve(res)
        })
      })
    }
  },
  mounted() {
    // ...
  }
}

export default Mixin_Toolbar